package com.example.demo.servlet;

import com.example.demo.dao.BookDao;
import com.example.demo.entity.BookVo;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/findbooks")
public class FindBooks extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String query = req.getParameter("query");
        try {
            List<BookVo> books = new BookDao().findBooks(query);
            req.setAttribute("books",books);
            req.getRequestDispatcher("/bookmanage.jsp").forward(req,resp);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
